from typing import List

from ninja import Router, Query
from ninja.pagination import paginate

from apps.manager.water_card_transfer_record.schema import WaterCardTransferRecordResponseSchema, \
    WaterCardRecordTransferFilterSchema
from models.models import WaterCardTransferRecord
from utils.auth import ManagerAuthBearer
from utils.decorators import handle_exception
from utils.paginations import MyPagination

manager_water_card_transfer_router = Router(tags=["水卡划拨记录"], auth=ManagerAuthBearer())


@manager_water_card_transfer_router.get("/water_card_transfer_records", summary="水卡记录列表",
                                        response=List[WaterCardTransferRecordResponseSchema])
@handle_exception("获取水卡记录列表失败")
@paginate(MyPagination)
def get_water_card_records(request, filters: WaterCardRecordTransferFilterSchema = Query(...), is_total=True):
    """
    获取水卡记录列表
    """
    records = WaterCardTransferRecord.objects.all()
    records = filters.filter(records)
    return records
